package xin.marcher.wind.migrate.task;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;
import xin.marcher.wind.migrate.mapper.EtlBinlogConsumeRecordMapper;

import javax.annotation.Resource;
import java.util.Date;

/**
 * 定时任务移除掉已提交的增量同步消息
 */
@Slf4j
@Component
public class RemoveBinlogConsumeTask {

    /**
     * binlog 消息同步消费记录表 Mapper
     */
    @Resource
    private EtlBinlogConsumeRecordMapper consumeRecordMapper;

    @Scheduled(cron = "0 0 0 1/1 * ? ")
    public void task() {
        // 每次删除超过当前时间 5 分钟的历史数据
        DateTime updateTime = DateUtil.offsetMinute(new Date(), -5);
        consumeRecordMapper.deleteCommittedConsumedRecords(updateTime);
    }
}
